Skip to content

Conversation

emensch
Copy link
Contributor

@emensch emensch commented Sep 4, 2025

  • Add c2pa-types package with logic to automatically generate TS types from c2pa-rs using schemars and json-schema-to-typescript.
  • Add activeManifest and manifestStore methods to the reader, taking advantage of these shiny new types for their output.

Copy link

changeset-bot bot commented Sep 4, 2025

🦋 Changeset detected

Latest commit: f3626e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@contentauth/c2pa-types Minor
@contentauth/c2pa-wasm Minor
@contentauth/c2pa-web Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@emensch emensch force-pushed the types-api-updates branch 2 times, most recently from 0b1b924 to 80d4eaa Compare September 9, 2025 06:48
Copy link

@gpeacock gpeacock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks ok to me, but I'm fuzzy on how you deal with resources, how do you read a thumbnail?

"version": "0.1.1",
"types": "index.d.ts",
"scripts": {
"test": "echo \"No tests to run\" && exit 0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep it then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of an annoying hangup with the monorepo system I'm using right now (NX). It expects a "test" command to be available for each published package and will error out if there's no command to run, so I've put this in place to get around that.

Frankly I'll be looking to get off of NX quite soon following this and would happily revisit this when I migrate.

edition = "2024"

[dependencies]
c2pa = { version = "0.62.0", features = ["pdf", "rust_native_crypto", "json_schema"], default-features = false }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the pdf feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just matching the features of the V1 SDK. I don't know if clients actively need this but we do support PDFs on Verify right now and the plan is to migrate that site to use this SDK.


import type { Reader } from './types/ManifestStore.js';

// Renames the auto-generated "Reader" type to the more appropriate "ManifestStore"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ManifestStore because you only deal with the "extracted" JSON afterwards?

Copy link
Contributor Author

@emensch emensch Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type really is just a ManifestStore despite being called a "Reader," and if I don't rename it I think it will be confusing to consumers. I.e. "why does Reader.manifestStore() return a Reader?"

/// Returns the asset's manifest store.
/// NOTE: at the moment, CAWG data is not decoded via this function. Use WasmReader::json() if CAWG is a requirement.
#[wasm_bindgen(js_name = manifestStore)]
pub fn manifest_store(&self) -> Result<JsValue, JsError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what it's doing, but what is the intend? Why is the manifest store by itself needed somewhere? (Especially because I see the js below: const manifestStore = await reader.json();, so it puzzles me a bit). Why is Reader.json() not usable all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to get rid of json in favor of manifest_store only. The output is very similar but not exactly the same. Two things:

  1. The types generated in this PR only correspond to the output of serializing a reader, not calling Reader::json. They are close but not identical.
  2. It looks like we can only get CAWG data through json() right now, unless I'm mistaken. Serializing a reader in this way seems to sidestep the post_validate_async hook.

I'm hopeful that once @scouten-adobe is able to land contentauth/c2pa-rs#1370 and these methods return CAWG correctly, I can just get rid of json() and use these typed APIs only.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, sounds good!

const reader = readerMap.get(readerId);
return { data: reader.activeManifest() };
},
reader_json(readerId: number): WorkerResponse<string> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused why we need both reader_json and reader_manifestStore?
Shouldn't reader.manifestStore() be a subset of reader.json()?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unconfused now - #11 (comment) is a realted great explanation.

@emensch
Copy link
Contributor Author

emensch commented Sep 9, 2025

@gpeacock this PR is only updating the API, a previous PR landed the "foundational" stuff, including resource store access. See that here: https://github.com/contentauth/c2pa-js-v2/pull/1/files#diff-2847b4b683a0f1f6efd121cb960f49946e99ea9c85afdd7687abfe571d538e44R58

@emensch emensch merged commit f21c81d into main Sep 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants